package com.jiyun;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.concurrent.TimeUnit;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class SpringdataRedisDemo_String {

    @Autowired
    RedisTemplate redisTemplate;

    /*
    string类型增删改查  key—value
     */

    @Test
    public void add(){
        //redisTemplate.boundValueOps("name").set("张三");
        //redisTemplate.boundValueOps("name").set("李四",10, TimeUnit.SECONDS);
        redisTemplate.boundValueOps("name").expire(10, TimeUnit.SECONDS);
    }

    @Test
    public void query(){
        String name =(String) redisTemplate.boundValueOps("name").get();
        System.out.println(name);
    }

    @Test
    public void del(){
        redisTemplate.delete("name");
    }

}
